<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <title>lianxi</title>
        <link rel="stylesheet" href="css/personal.css">
        <link rel="stylesheet" href="css/mui.min.css">
        <link rel="stylesheet" href="../public_css/public_header.css">
        <script src="js/jquery-1.8.3.min.js"></script>
        <script src="js/mui.min.js"></script>
        <script src="js/personal.js"></script>
        <script src="../jquery.min.js	"></script>
    </head>
    <body>
         <header class=" public_header">
            <div class="public_header_return">
                <img src="../public_img/return.png" alt="" class="public_header_return" onclick="history.back(-1)">
                <p>个人资料</p>
            </div>
        </header>
        <!--nav结束-->

        <div class="content"><!--内容-->
            <div class="name">
                <span>头像</span><img src="../public_img/edit.png" alt="" style="width: 0.5rem; height: 0.5rem; vertical-align: middle; margin-left: 0.2rem;">
                <input type="file" name="file" onchange="UpladFile()" class="file" id="file" size="28"  style="display: none"/>
                <img class="portrait"  src="http://image.icandrive.cn/herderimg.jpg">
            </div>
            <ul class="item_wrap">
                <li>
                    <span>姓名</span>
                    <input type="text" class="name" placeholder="未设置" disabled>

                </li>
                <li id="iten1">
                    <span>职业</span>
                    <img src="../public_img/edit.png" alt="" id="item_img">
                    <input type="text" class="work" placeholder="未设置" id="item_input"  >
                </li>
                <li>
                    <span>电话</span>
                    <input type="text" class="phone" placeholder="未设置" disabled>
                </li>
                <li>
                    <span>身份证号码</span>

                    <input type="text"  class="id_number" placeholder="未设置" disabled>
                </li>


            </ul>
            <div style="width:100% ; text-align: center"  >
                <button  onclick="save_self()" id="abtn"> 确认</button>
            </div>
        </div><!--content结束-->


        <!--<nav class="base">&lt;!&ndash;底部导航&ndash;&gt;-->
        <!--<a class="active" href="" style="margin-left: 0.001rem">-->
        <!--<span><img src="img/apply.png" alt=""></span>-->
        <!--<span>报名</span>-->
        <!--</a>-->
        <!--<a class="active" href="">-->
        <!--<span class=""><img src="img/teaching.png" alt=""></span>-->
        <!--<span>约教</span>-->
        <!--</a>-->
        <!--<a class="active" href="">-->
        <!--<span><img src="img/exercise.png" alt=""></span>-->
        <!--<span>练题</span>-->
        <!--</a>-->
        <!--<a class="active" href="">-->
        <!--<span><img src="img/personage1.png" alt=""></span>-->
        <!--<span style="color: #f39839">我</span>-->
        <!--</a>-->
        <!--</nav>&lt;!&ndash;结束&ndash;&gt;-->


        <script>
            $(function () {
                var token=localStorage.phone;

                $.ajax({
                    url:"https://newapp.icandrive.cn/api/set.php",
                    type:'post',
                    dataType:'json',
                    data:{token:token},
                    success: function (data) {
                        if(data.status==200){
                            $(data.dataing).each(function () {


                                //页面加载获取登陆电话号码  在index查询到的
                                var	change_hidden_phone = (this.id_number).substring(0,10) + "*****" + (this.id_number).substring(this.id_number.length - 3);


                                $('.portrait').attr('src',this.photo);
                                $('.name').val(this.user_name);
                                $('.id_number').val(change_hidden_phone);
                                $('.phone').val(this.phone);
                                $('.work').val(this.work);
                            })
                        }
                    },
                    error: function () {
                    }
                })
                $('.name img').click(function () {
                    $('.name input[type=file]').click();
                })
            })

            var xhr;

            function createXMLHttpRequest() {
                if (window.ActiveXObject) {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                } else if (window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest();
                }
            }

            function UpladFile() {
                var f=document.getElementById("file").value;
                if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(f))
                {
                    layer.msg("请选择正确格式的图片");
                    return false;
                }
                var token=localStorage.phone;
                var fileObj = document.getElementById("file").files[0];
                var FileController = 'https://newapp.icandrive.cn/api/student_photo.php?token='+token;
                var form = new FormData();
                form.append("myfile", fileObj);
                createXMLHttpRequest();
                xhr.onreadystatechange = handleStateChange;
                xhr.open("post", FileController, true);
                xhr.send(form);
            }
            function handleStateChange() {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200 || xhr.status == 0) {
                        var result = xhr.responseText;
                        var json = eval("(" + result + ")");
                        setTimeout(function(){
                            history.go(0)
                        },2000)

                    }
                }
            }
            function save_self(){
                var token=localStorage.phone;
                var work=$('.work').val();
                //        var phone=$('.phone').val();


                $.ajax({
                    url:'https://newapp.icandrive.cn/api/set_self.php',
                    data:{token:token,work:work},
                    dataType:'json',
                    type:'post',
                    success: function (data) {
                        if(data.status==200){
                            alert('保存成功')
                        }else{
                            alert('系统繁忙，请稍后再试')
                            history.go(0)
                        }

                    },
                    error: function () {

                    }

                })
            }
        </script>

        <script>
            document.addEventListener("plusready", function() {
                // 注册返回按键事件
                plus.key.addEventListener('backbutton', function() {
                    window.history.back();
                }, false);
                //此处false代表不退出页面，如果为true回退到上一个一面
            });
        </script>
    </body>
</html>
